package academic.concordia.bankofquebec.entity;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue(value="INVESTMENT_ACCOUNT")
public class MutualFunds extends InvestmentAccount implements Serializable{

	private static final long serialVersionUID = 1L;
	private double minimumTransferAmount;
	private double minimumBalanceAmount;

	public MutualFunds(){
		super();
		this.attributes = AccountAttributes.MUTUAL_FUNDS;
		this.type = this.attributes.name();
		this.setTimePeriod(Calendar.DAY_OF_MONTH);
		this.setPeriodicity(1);
		this.setStatus(BankAccountStatus.PENDING_INITIAL_INVESTMENT);
		this.setAnnualInterestRate(5);
		this.minimumBalanceAmount = 100;
		this.minimumTransferAmount = 100;
		this.calculateInterestPaymentDate();
	}
	
	public double getMinimumBalanceAmount() {
		return minimumBalanceAmount;
	}

	public void setMinimumBalanceAmount(double minimumBalanceAmount) {
		this.minimumBalanceAmount = minimumBalanceAmount;
	}

	public void setMinimumTransferAmount(double minimumTransferAmount) {
		this.minimumTransferAmount = minimumTransferAmount;
	}

	public Transaction deposit(double amount){
		Transaction deposit = null;
		
		if (amount < this.minimumTransferAmount)
			return deposit;
		
		deposit = super.deposit(amount);
		return deposit;
	}
	
	public Transaction withdrawal(double amount){
		Transaction withdrawal = null;
		
		if ((this.getBalance()-amount) < this.minimumBalanceAmount)
			return withdrawal;
		
		withdrawal = super.withdraw(amount);
		return withdrawal;
	}
	
	public double calculateInterests(){
		return super.calculateInterests() /365;
	}
	
	public Transaction depositInterests(double amount){
		Transaction transaction = super.depositInterests(amount);
		setInvestedAmount(getBalance());
		return transaction;
	}
	
}
